package com.atguigu.gulimall.order.controller;

import com.atguigu.gulimall.order.entity.OrderReturnReasonEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.UUID;
@Controller
@Slf4j
public class RabbitController {
    @Autowired
    RabbitTemplate rabbitTemplate ;
    @ResponseBody
    @GetMapping("/sendMq")
    public String sendMessageTest() throws InterruptedException {
        String msg = "Hello world";
        for(int i = 0;i<10;i++){
            if(i%2 == 0){
                OrderReturnReasonEntity memberRespVo = new OrderReturnReasonEntity();
                memberRespVo.setId(18270812217l);
                memberRespVo.setName("基"+i);
                rabbitTemplate.convertAndSend("hello-java-exchange","helo.java",memberRespVo);
//                log.info("消息发送完成:[{}]",memberRespVo);
            }else {
                OrderReturnReasonEntity member = new OrderReturnReasonEntity();
                member.setName(UUID.randomUUID().toString());
                rabbitTemplate.convertAndSend("hello-java-exchange","helo.java",member);
            }
            log.info("消息发送完成:[{}]");
        }
        return "ok";
    }
}
